# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=lsp
pkgname=haskell-lsp
pkgver=1.6.0.0
pkgrel=58
pkgdesc="Haskell library for the Microsoft Language Server Protocol"
url="https://github.com/haskell/lsp"
license=("MIT")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-aeson' 'haskell-async' 'haskell-attoparsec' 'haskell-co-log-core'
         'haskell-data-default' 'haskell-hashable' 'haskell-lens' 'haskell-lsp-types'
         'haskell-prettyprinter' 'haskell-random' 'haskell-sorted-list' 'haskell-temporary'
         'haskell-text-rope' 'haskell-unliftio-core' 'haskell-unordered-containers' 'haskell-uuid'
         'haskell-unliftio')
makedepends=('ghc' 'uusi' 'haskell-hspec' 'haskell-hspec-discover')
source=("https://hackage.haskell.org/packages/archive/$_hkgname/$pkgver/$_hkgname-$pkgver.tar.gz")
sha512sums=('e943409c6321d87178b8ac2e331ee67e259df9661a7ad4e0d30238ea79b29e79129b45bdb25d420e633e7e74c632ce6f1a1ba6e6a3ead2e0c47db5a3418cf476')

prepare() {
  cd $_hkgname-$pkgver
  gen-setup
  uusi -u sorted-list $_hkgname.cabal
}

build() {
  cd $_hkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie' \
    -fdemo

  runhaskell Setup build $MAKEFLAGS
  runhaskell Setup register --gen-script
  runhaskell Setup unregister --gen-script
  sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
  cd $_hkgname-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $_hkgname-$pkgver

  install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
  install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
